
<?php
// array for JSON response
$response = array();
include("conn.php");
// check for required fields
if (isset($_GET['username'])) {
    
    $name = $_GET['username'];
    $result = mysql_query("select * from mydb where username like '$name'");// check if row inserted or not
    //echo $result;
	if ($result) {
        // successfully 
		$rows=mysql_num_rows($result);
		if($rows>0)
		{
			$response["success"] = 1;
			$response["message"] = "success.already existed.";
	
			//echoing JSON response
			echo json_encode($response);
		}
		else
		{	
			$response["success"] = 0;
			$response["message"] = "success.not existed.";
	
			//echoing JSON response
			echo json_encode($response);
		
		}
    } else {
        // failed 
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";
        
        // echoing JSON response
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}
?>

